﻿using Jst.Core.Utility;
using Microsoft.Extensions.DependencyInjection;

namespace Jst.Infrastructure.DbFirst
{
    /// <summary>    
    /// /// 数据库实体生成器（一次性任务）     
    /// /// </summary>    
    public class DbEntityGenerator
    {
        private readonly IServiceProvider _serviceProvider;

        /// <summary>         
        /// /// 构造函数注入服务提供器         
        /// /// </summary>         
        public DbEntityGenerator(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }
        /// <summary>        
        /// /// 执行数据库实体生成（一次性操作）         
        /// /// </summary>         
        public void GenerateEntitiesOnce()
        {

            if (AppSettingsConstVars.DbEntityGenerator)
            {
                using (var scope = _serviceProvider.CreateScope())
                {
                    var job = scope.ServiceProvider.GetRequiredService<TempDbFirstJob>();
                    job.RunOnce();
                }
            }
        }
    }
}
